#ifndef USERDIALOG_H
#define USERDIALOG_H
#include "touchbutton.h"
#include <QVBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QComboBox>
#include <QPushButton>
#include <QGraphicsDropShadowEffect>
#include <QDialog>
#include <QListView>
#include <popupdialog.h>

class UserDialog : public PopupDialog
{
    Q_OBJECT

public:
    enum DialogType {
        Add,
        Edit
    };

    enum UserRole {
        Developer=0,
        Normal
    };

    explicit UserDialog(DialogType type, QWidget *parent = nullptr);
    void setUserData(const QString &name = "", UserRole role = Normal, const QString &password = "");
    void setError(QString strErr);
    QString getUserName() const;
    QString getPassword() const;
    UserRole getUserRole() const;

protected  slots:
    void textChanged(const QString &strText);
private:
    void initUI();

private:
    DialogType dialogType;
    QLineEdit *nameEdit;
    QLineEdit *passwordEdit;
    QComboBox *roleComboBox;
    
    QPoint dragPosition;
    QLabel *titleLabel;
    TouchButton *closeButton;
    QGraphicsDropShadowEffect *shadowEffect;
    QString strOldUserName;
    QString strError="";
    QLabel *errLabel=nullptr;
    bool bPwdTextIsChanged=false;
public slots:
    void accept();
};

inline QString UserDialog::getUserName() const { return nameEdit->text(); }

inline QString UserDialog::getPassword() const { return passwordEdit->text(); }

inline UserDialog::UserRole UserDialog::getUserRole() const { return static_cast<UserRole>(roleComboBox->currentIndex()); }

#endif // USERDIALOG_H 
